import api from './index'
import { axios } from '@/utils/request'
import storage from 'store'

/**
 * login func
 * parameter: {
 *     username: '',
 *     password: '',
 *     remember_me: true,
 *     captcha: '12345'
 * }
 * @param parameter
 * @returns {*}
 */
export function login (parameter) {
  return axios({
    url: '/backvd/login',
    method: 'post',
    data: parameter
  })
}

export function loginSms (parameter) {
  return axios({
    url: '/sys/admin/user/sms-validation/login',
    method: 'post',
    data: parameter
  })
}

export function getSmsCaptcha (parameter) {
  return axios({
    url: '/sys/admin/user/sms/code',
    method: 'post',
    data: parameter
  })
}

export function getInfo () {
  return axios({
    url: '/admin/user/view/' + storage.get('user_id'),
    method: 'get'
  })
}

export function getCurrentUserNav () {
  return axios({
    url: '/sys/admin/menu/mine',
    method: 'post'
  })
}

export function logout () {
  return axios({
    url: '/auth/logout',
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function googleGen (parameter) {
  return axios({
    url: '/backvd/googleAuth/gen',
    method: 'post',
    data: parameter,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

export function googleAuth (parameter) {
  return axios({
    url: '/backvd/googleAuth/auth',
    method: 'post',
    data: parameter,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
  export function getUser (parameter) {
    return axios({
      url: '/backvd/googleAuth/getUser',
      method: 'post',
      data: parameter,
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
}


/**
 * get user 2step code open?
 * @param parameter {*}
 */
export function get2step (parameter) {
  return axios({
    url: api.twoStepCode,
    method: 'post',
    data: parameter
  })
}
